﻿<%@ WebHandler Language="C#" Class="_default" %>

using System;
using System.Web;
using System.Data;
using NS.Utilities;
using WechatUtility;
using BLL;
using Model;

public class _default : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        string result = string.Empty;

        if (string.IsNullOrEmpty(context.Request["code"]))
        {
            string url = "http://" + context.Request.Url.Host + "/wechat/default.html";
            result = JsonMessager.Success(Wechat.GetOAuthBasePublic(url));
        }
        else
        {
            //获取用户的openid
            Wechat wc = new Wechat();
            string openid = wc.GetOpenid(context.Request["code"]);
            //string openid = "oNqrqjrO9z53O-0lCFb60QGufjaw";
            //string openid = "o2kRpuM10wCIlM3wZwbfgtv-AqmQ";
            if (!string.IsNullOrEmpty(openid))
            {
                CookieHelper.SetObject("openid", 7200, openid);
                result = JsonMessager.Success("ok");
            }
            else
            {
                result = JsonMessager.Fail("微信登录失败");
            }
        }
        context.Response.Write(result);
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}